#!/bin/bash

rootdir=$(dirname $(dirname $(realpath $0)))

source $rootdir/config/echo_config || exit 1

echo_start "set"
if ! {
    cp $RESOURCE_DIR/LiveCD_vimrc /etc/vimrc &&
    yes q|passwd &&
    systemctl start sshd &&
    ip addr | grep -E 'inet .* global' &&
    sed -i 's/nameserver .*/nameserver 114.114.114.114/g' /etc/resolv.conf &&
    cp $RESOURCE_DIR/archlinuxcn-mirrorlist /etc/pacman.d/archlinuxcn-mirrorlist
}; then
    echo_err "set"
    exit 1
fi
if [ -z $1 ]; then
    if ! {
        reflector --verbose --country China -p http --sort rate --save /etc/pacman.d/mirrorlist &&
        pacman -Sy
    }; then
        echo_err "set"
        exit 1
    fi
fi
echo_finish "set"
echo_start "git"
if ! {
    command -v git > /dev/null || pacman -S --noconfirm git
}; then
    echo_err "git"
    exit 1
fi
pushd $rootdir
if ! {
    git config --global --add safe.directory $rootdir &&
    git config user.name mewiteor &&
    git config user.email mewiteor@hotmail.com
}; then
    popd
    echo_err "git"
    exit 1
fi
popd
echo_finish "git"
